package com.notes.designpattern.chain.handler;

import com.alibaba.fastjson.JSON;
import com.notes.designpattern.chain.BusinHandler;
import com.notes.designpattern.chain.BusinHandlerChain;
import com.notes.designpattern.chain.domain.*;


/**
 * @author
 * @Describe 功能描述
 * @date
 */
public class BusinOneHandler implements BusinHandler<BusinOneReq, BusinOneBO, BusinOneResp> {

    String businName;
    public BusinOneHandler(String businName) {
        this.businName = businName;
    }

    @Override
    public BusinOneResp process(BusinOneReq req, BusinOneBO baseBO, BusinHandlerChain businHandlerChain) {
        System.out.println("开始执行" + this.businName + "入参: " + JSON.toJSONString(req));
        BusinOneResp businOneResp = new BusinOneResp();
        if (this.businName.equals("BusinOneHandler")) {
            businOneResp.setBusinResp("BusinOneHandler");
            System.out.println("开始执行" + this.businName + "成功，出参: " + JSON.toJSONString(businOneResp));
            BusinTwoReq nextChainReq = new BusinTwoReq();
            nextChainReq.setBusinKey("BusinTwoHandler");
            nextChainReq.setBusinOneBaseResp(businOneResp);
            businHandlerChain.process(nextChainReq, new BusinTwoBO(), businHandlerChain);
            return businOneResp;
        }
        businOneResp.setErrorNo(-1);
        System.out.println("开始执行" + this.businName + "失败，出参: " + JSON.toJSONString(businOneResp));
        return businOneResp;
    }
}
